<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script
  src="https://code.jquery.com/jquery-3.6.1.js"
  integrity="sha256-3zlB5s2uwoUzrXK3BT7AX3FyvojsraNFxCc2vC/7pNI="
  crossorigin="anonymous"></script>
    <title>Document</title>
    <script>
        $(function(){
            var sum = 0;
            var arr = ["red","green","blue"]
            $("div").css("color","red")
            // 如果针对同一类元素做不同操作，需要到遍历元素（类似for，但是比for强大）
            $("div").each(function(index,domEle){
                console.log(index)   // 0 1 2
                console.log(domEle);  // <div>1</div>   <div>2</div> <div>3</div>
                $(domEle).css("color",arr[index])
                sum += parseInt($(domEle).text())

            })
            console.log(sum)
            // 2,$.each()方法遍历元素  主要用于遍历数据。处理数据
            // $.each($("div"),function(i,ele)
            // {
            //     console.log(index)


            // })
            $.each({
                name:"andy",
                age:18
            })
            
        })
    </script>
</head>
<body>
     <div>1</div>
     <div>2</div>
     <div>3</div>
</body>
</html>